package org.apache.lucene.ocean.util;

import java.io.IOException;

import org.apache.lucene.store.IndexInput;

public class ByteArrayIndexInput extends IndexInput {
  private byte[] bytes;
  protected int pos = 0;
  
  public ByteArrayIndexInput(byte[] bytes) {
    this.bytes = bytes;
  }
  
  public byte readByte() throws IOException {
    return bytes[pos++];
  }

  public void readBytes(byte[] b, int offset, int len) throws IOException {
    if (pos + len > bytes.length) {
      len = bytes.length - pos;
    }
    System.arraycopy(bytes, pos, b, offset, len);
    pos += len;
  }

  public void close() throws IOException {
  }

  public long getFilePointer() {
    return pos;
  }

  public void seek(long pos) throws IOException {
    this.pos = (int)pos;
  }

  public long length() {
    return bytes.length;
  }
}
